import socket
from NetWorkLayer.IPv4 import IPv4
from TransmitLayer.TCP import TCP
from LinkLayer.Mac import Mac
from ApplicationLayer.Socket import Socket

src_ip="192.168.1.5"
dst_ip="192.168.1.2"
data="appl"

mySocket = Socket(dst_ip,0)
myTCP = TCP(src_ip=src_ip,
                dst_ip=dst_ip,
                weikeep=0,
                protocol_id=6,
                total_len=0,
                src_port=1000,
                dst_port=80,
                seq=0,
                ack=0,
                head_len=5,
                keep=0,
                URG=0,
                ACK=0,
                PSH=0,
                RST=0,
                SYN=1,
                FIN=0,
                windowSize=3000,
                checkSum=0,
                UrgPtr=0,
                other=None,
                data=data
                )
TCP_pack = myTCP.getPack()
myIpv4 = IPv4(IP_version=4, 
              IP_head_len=5,
              server_kind=0,
              Total_len=0,
              identification=2222,
              flag=2,#010-->不分片，无分片
              Fragment_offset=0,#无分片=0
              TTL=255,# TTL 的初始值设为 1，则表示这个数据报只能在本局域网中传送
              protocol=6,#TCP 的协议号为 6
              checkSum=0,#校验和先初始化为0，后计算填充
              src_ip=src_ip,
              dst_ip=dst_ip,
              data=TCP_pack
              )

IPv4_pack = myIpv4.getPack()
print(IPv4_pack)
# myMac = Mac(dst_mac=b"\x00\x00\x00\x00\x00\x00",
            # src_mac=b"\x00\x00\x00\x00\x00\x00",
            # datatype=b"\x08\x00",
            # data=IPv4_pack,
            # FCS=b"")
# MAC_pack = myMac.getPack()
# print(MAC_pack)
mySocket.send(IPv4_pack)